<?php
include_once 'header_php.php';
$title='Trésorerie';
include_once 'header_html.php';
$asso=$_GET['asso'];
if(isset($_GET['bilan'])){
    $bilan=$_GET['bilan'];
    $sem=$_GET['sem'];
}



?>
<div class="wrapper">
		<div class="span2"><ul class="nav nav-list"><li><a href="asso.php?nom=<?php echo $_GET['asso'];?>"><i class="icon-chevron-left"></i> <?php echo $_GET['asso'];?></a></li></ul></div>
		<div class="container-fluid span8">
                    <br/><br/>
                    <h3>
                        Trésorerie de <?php echo $asso; ?>
                    </h3>
                    <br/><br/><br/>
                    <?php
                        
                    echo'<table class="table table-striped">';
                    echo'<thead>';
                    echo'<tr>';
                    echo '<th>ID Transaction</th><th>Semestre</th><th>Trésorier</th><th>Intitulé</th><th>Type de la transaction</th><th>Montant</th>';
                    echo'</tr>';
                    echo'</thead>';
                    echo '<tbody>';
                    
                    $sql = "SELECT semestre, numfacture, personne, intitule, type, montant FROM membreasso MA, transaction T WHERE MA.association='".$asso."' AND T.tresorier=MA.id; ";
                    $querySql= new DbQuery($db,$sql);
                    $querySql->SendQuery();
                    while($result=$querySql->GetResult()){
                        echo '<tr>';
                        echo '<td>'.$result['numfacture'].'</td>';
                        echo '<td>'.$result['semestre'].'</td>';
						$trez=new Personne($result['personne']);
						$trez->FillFromLogin($db);
						
                        echo '<td>'.$trez->GetNomComplet().'</td>';
                        echo '<td>'.$result['intitule'].'</td>';
                        echo '<td>'.$result['type'].'</td>';
                        echo '<td>'.$result['montant'].'</td>';
                        echo '</tr>';
                        }
                    echo  '</tbody>';
                    echo '</table>';
                    
                    $sql = "SELECT soldecompte FROM association A WHERE A.nom='".$asso."';";
                    $querySql= new DbQuery($db,$sql);
                    $querySql->SendQuery();
                    $result=$querySql->GetResult();
                    echo "Solde du compte : ".$result['soldecompte']." €";
                    ?>
                    <br/>
                    <br/>
                    <br/>
                    <br/>
                    <form class="form-horizontal" action="calcul.php?asso=<?php echo $asso; ?>" method="POST" accept-charset="UTF-8">
                        <fieldset>
                            <legend>Calculer le bilan d'un semestre</legend>
                            <div class="control-group">
                                <div class="controls">
                                    <select id="semestre" name="semestre">
                                        <?php
                                        $sql = "SELECT DISTINCT semestre FROM membreasso MA, transaction T WHERE MA.association='".$asso."' AND T.tresorier=MA.id; ";
                                        $querySql= new DbQuery($db,$sql);
                                        $querySql->SendQuery();
                                        while($result=$querySql->GetResult())
                                        {
                                            echo '<option value="'.$result['semestre'].'">'.$result['semestre'].'</option>';
                                        }

                                        ?>
                                    </select>

                                </div>
                            </div>
                            <div class="form-actions">
                                <button type="submit" class="btn btn-primary">Calculer le bilan</button>
                                <?php
                                    if(isset($bilan))
                                        echo "Bilan pour le semestre ".$sem." : ".$bilan."€";
                                ?>
                            </div>

                        </fieldset>
                    </form> 
                    
                </div>
    
</div><!-- /container -->


<?php 
    //include_once 'footer.php'; 
?>
